import logging
import uvicorn
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from pathlib import Path
from app.controller.course_controller import router as course_router
from app.template_config import templates

# 获取项目根目录
BASE_DIR = Path(__file__).resolve().parent.parent

# 初始化FastAPI应用
app = FastAPI(title="课程管理", version="1.0")

# 配置静态文件目录（用于存放CSS、JavaScript等）
app.mount("/static", StaticFiles(directory=str(BASE_DIR / "static")), name="static")

logger = logging.getLogger(__name__)

# 注册路由
app.include_router(course_router)

@app.get("/")
def root(request: Request):
    return templates.TemplateResponse("index.html", {"request": request, "messages": []})

@app.get("/health")
def health_check():
    return {"status": "healthy"}


# 可以通过以下命令来启动项目:
# uv run python -m app.main
if __name__ == "__main__":
    uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)